package com.zcxy.fast.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zcxy.fast.bean.PageQuery;
import com.zcxy.fast.entity.SysRole;
import com.zcxy.fast.vo.SysRoleVo;
import com.zcxy.fast.service.ISysRoleService;
import com.zcxy.fast.mapper.SysRoleMapper;
import com.zcxy.fast.mybatisExtend.BaseServiceImpl;
import com.zcxy.fast.utils.BeanCopyUtil;
import com.zcxy.fast.utils.StringUtils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;



/**
 * 平台-角色表业务层处理
 *
 * @author zcc
 * @email  860474958@qq.com
 * @date   2021-01-06 17:10:37
 */
@Service
@Slf4j
public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

    @Override
    public IPage<SysRoleVo> queryPageList(PageQuery<SysRole> queryVo) {
        SysRole sysRole=queryVo.getT() == null ? new SysRole() : queryVo.getT();
        QueryWrapper queryWrapper = new QueryWrapper();
        Page page = new Page(queryVo.getPageNo(), queryVo.getPageSize());
            if(StringUtils.isNotEmpty(sysRole.getRoleName())){
            queryWrapper.like("role_name",sysRole.getRoleName());
        }
        IPage<SysRole> sysUserVoIPage = baseMapper.selectPage(page, queryWrapper);
        return BeanCopyUtil.copyPage(sysUserVoIPage, SysRoleVo.class);
    }

    @Override
    public List<SysRoleVo> queryList(SysRole sysRole) {
        SysRole sysRoleq=sysRole == null ? new SysRole() : sysRole;
        QueryWrapper queryWrapper = new QueryWrapper(sysRoleq);
        List<SysRoleVo> SysRoleVos=BeanCopyUtil.copyListToList(baseMapper.selectList(queryWrapper),SysRoleVo.class);
        return SysRoleVos;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addSysRole(SysRole sysRole) {

        baseMapper.insert(sysRole);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateSysRole(SysRole sysRole) {
        baseMapper.updateById(sysRole);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removeAllSysRole(List<String> ids) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.in("id", ids);
        baseMapper.delete(queryWrapper);
    }



}
